home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / ab20 / ab20_archive / utilities / file / whereis.lzh / date.c next >
C/C++ Source or Header  |  1991-02-16  |  838b  |  54 lines

  1. #ifndef datetype
  2.  #include "date.h"
  3. #endif
  4. #ifndef EXEC_TYPES_H
  5.  #include <exec/types.h>
  6. #endif
  7.  
  8. ULONG leapyear (year)
  9. ULONG year;
  10.  
  11. {
  12.   return (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? 366L : 365L;
  13. }
  14.  
  15.  
  16. void date(datep, days)
  17. struct date *datep;
  18. register ULONG days;
  19. {
  20.   register ULONG year=1978L, month=0L;
  21.  
  22.   static ULONG DaysofMonth[]=
  23.   { 31L, 28L, 31L, 30L,
  24.     31L, 30L, 31L, 31L,
  25.     30L, 31L, 30L, 31L };
  26.  
  27.   year=1978L;
  28.   while (days >= 366L)
  29.   {
  30.     days-= leapyear(year);
  31.     year++;
  32.   }
  33.   if (days == 365L && leapyear(year)!= 366L)
  34.   {
  35.     days-=365L;
  36.     year++;
  37.   }
  38.  
  39.   DaysofMonth[1]= leapyear(year)==366L? 29L : 28L;
  40.  
  41.   while (days >= DaysofMonth[month])
  42.   {
  43.     days-=DaysofMonth[month];
  44.     month++;
  45.   }
  46.  
  47.   days++;
  48.   month++;
  49.  
  50.   datep->day= (short) days;
  51.   datep->month= (short) month;
  52.   datep->year= year;
  53. }
  54.